import dynamicProxy.JDKDynamicProxy;
import dynamicProxy.Person;
import dynamicProxy.Tiger;
import dynamicProxy.Worker;
import staticProxy.Animal;
import staticProxy.IAnimal;
import staticProxy.ProxyAnimal;

import java.lang.reflect.Proxy;

/**
 * @Author Yenchingcheng
 * @Date 2023/6/13 19:00
 * @Description 测试类
 **/
// Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`,
// then press Enter. You can now see whitespace characters in your code.
public class Main {
    public static void main(String[] args) {
        /**1.测试静态代理类*/
        IAnimal iAnimal = new Animal();
        ProxyAnimal proxyAnimal = new ProxyAnimal(iAnimal);
        proxyAnimal.eat();
        /**2.测试动态代理*/
        JDKDynamicProxy proxy1 = new JDKDynamicProxy(new Tiger("泰哥"));
        dynamicProxy.Animal tiger = (dynamicProxy.Animal) Proxy.newProxyInstance(proxy1.getClass().getClassLoader(),new Class[]{dynamicProxy.Animal.class},proxy1);
        tiger.sleep();
        tiger.wakeUp();

        JDKDynamicProxy proxy2 = new JDKDynamicProxy(new Worker("卫国"));
        Person worker = (Person) Proxy.newProxyInstance(proxy2.getClass().getClassLoader(),new Class[]{Person.class},proxy2);
        worker.sleep();
        worker.wakeUp();
    }
}